package bean;

import java.io.IOException;
import java.sql.*;

import javax.sql.*;

import java.util.ArrayList;


import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



public class ServletDBPool extends HttpServlet {

	private static final long serialVersionUID=1l;
	private Connection conn=null;
	
	public ServletDBPool() {
		super();
		try
		{
			Context context = new InitialContext();
			DataSource source = (DataSource)context.lookup("java:comp/env/jbdc/OarcleDB");
			
			conn = source.getConnection();
		}
		catch(Exception ex)
		{
			
		}
		
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		ArrayList<MemberVo> al = new ArrayList<MemberVo>();
		String sql = "select * from member";
		
		try
		{
			PreparedStatement ps = conn.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			while(rs.next())
			{
				MemberVo vo = new MemberVo();
				vo.setMid("mid");
				vo.setIrum("irum");
				al.add(vo);
			}
			
			req.setAttribute("al", al);
			ServletContext servletContext = getServletContext();
			RequestDispatcher dispatcher = servletContext.getRequestDispatcher("/servlet/servlet_pool.jsp");
			dispatcher.forward(req, resp);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
	
	}

}
